//
//  FSEmoticonModel.m
//  FSWeiBo(Objc)
//
//  Created by lyw on 15/9/17.
//  Copyright (c) 2015年 cn.liuyawei. All rights reserved.
//

#import "FSEmoticonModel.h"

#define EMOJI_CODE_TO_SYMBOL(x) ((((0x808080F0 | (x & 0x3F000) >> 4) | (x & 0xFC0) << 10) | (x & 0x1C0000) << 18) | (x & 0x3F) << 24);

@implementation FSEmoticonModel

+ (instancetype)emoticonModelWithDict:(NSDictionary*)dict
{
    FSEmoticonModel* model = [[FSEmoticonModel alloc] init];
    [model setValuesForKeysWithDictionary:dict];
    return model;
}
- (void)setValue:(id)value forUndefinedKey:(NSString*)key
{

    //3+6*16*16+16*16+16*16*16
}
- (void)setValue:(id)value forKey:(NSString*)key
{
    if ([key isEqualToString:@"code"]) {
        NSString *str = [NSString stringWithFormat:@"%@",value];
        NSScanner *scanner = [NSScanner scannerWithString:str];
        unsigned result = 0;
        [scanner scanHexInt:&result];
        int sym = EMOJI_CODE_TO_SYMBOL(result);
        NSString* emoT = [[NSString alloc] initWithBytes:&sym length:sizeof(sym) encoding:NSUTF8StringEncoding];
        self.emoji = emoT;
        return;
    }
    [super setValue:value forKey:key];
}


- (NSString*)pngPath
{
    NSString* bundlePath = [[NSBundle mainBundle] bundlePath];
    NSString* pngPath = [NSString stringWithFormat:@"%@/Emoticons.bundle/%@/%@", bundlePath, self.id, self.png];
    return pngPath;
}



+(instancetype)initWithIsEmptyButton:(BOOL)isEmptyButton{
    [super init];
    
    FSEmoticonModel *emotionModel =[[self alloc] init];
    
    emotionModel.isEmptyButton=isEmptyButton;
    
    return emotionModel;
}

+(instancetype)initWithIsDeleteButton:(BOOL)isDeleteButton{
    [super init];
    
    FSEmoticonModel *emotionModel = [[self alloc]init];
    
    emotionModel.isDeleteButton =isDeleteButton;
    
    return emotionModel;

}

-(NSInteger)times{
    return 0;
}
@end
